import pymysql


def main():
    conn = pymysql.connect(host='42.192.52.196', port=3306, user='root', password='123456',
                           db='test', charset='utf8', cursorclass=pymysql.cursors.DictCursor)
    try:
        with conn.cursor() as cursor:
            # result = cursor.execute('insert into hrs values(90, "财务部", "上海")')
            # result = cursor.execute('update hrs set dloc=%s where dno=%s', (loc, no))
            # result = cursor.execute('delete from hrs where dno=10')
            cursor.execute('select dno, dname, dloc from hrs')
            for row in cursor.fetchall():
                print(row['dno'], end='\t')
                print(row['dname'], end='\t')
                print(row['dloc'], end='\t')
                print('-'*20)
            # if result == 1:
            #     print("删除成功")
            # conn.commit()
    except pymysql.MySQLError as error:
        print(error)
        conn.rollback()
    finally:
        conn.close()


if __name__ == '__main__':
    main()
